<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>跟进新客户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="lib/layui-v2.5.5/css/layui.css">
    <!--<link rel="stylesheet" href="css/layuimini.css">-->
    <link rel="stylesheet" href="css/public.css" media="all">
    <link rel="stylesheet" href="css/card.css">
</head>
<body>
<div class="layuimini-container ">
    <div class="layuimini-main">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md8">
                <div class="layui-card">
                    <div class="layui-card-header">客户联系信息</div>
                    <div class="layui-card-body layui-text">
                    <div class="layui-form-item layui-form-pane">
                        <div class="layui-inline">
                            <label class="layui-form-label">客户名称</label>
                            <div class="layui-input-inline">
                                <input type="text" id="custName" name="custName" autocomplete="off"
                                       placeholder="点击选择客户" class="layui-input" required lay-verify="required">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">客户ID</label>
                            <div class="layui-input-block">
                                <input type="text" id="custId1" name="custId1" placeholder="" autocomplete="off"
                                       class="layui-input" readonly="readonly">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">联系人</label>
                            <div class="layui-input-block">
                                <input type="text" id="custLinkman" name="custLinkman" placeholder=""
                                       autocomplete="off"
                                       class="layui-input" readonly="readonly">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">负责人ID</label>
                            <div class="layui-input-block">
                                <input type="text" id="custUserId" name="custUserId" placeholder=""
                                       autocomplete="off"
                                       class="layui-input" onkeyup="this.value=this.value.replace(/\D/g,'')"
                                       onafterpaste="this.value=this.value.replace(/\D/g,'')" readonly="readonly">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-pane">
                        <div class="layui-inline">
                            <label class="layui-form-label">电话</label>
                            <div class="layui-input-block">
                                <input type="text" id="custPhone" name="custPhone" placeholder="" autocomplete="off"
                                       class="layui-input" readonly="readonly">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">邮箱</label>
                            <div class="layui-input-block">
                                <input type="text" id="custEmail" name="custEmail" placeholder="" autocomplete="off"
                                       class="layui-input" readonly="readonly">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">邮政编码</label>
                            <div class="layui-input-block">
                                <input type="text" id="custZipcode" name="custZipcode" placeholder="" autocomplete="off"
                                       class="layui-input" readonly="readonly">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">地址</label>
                            <div class="layui-input-block">
                                <input type="text" id="custAddress" name="custAddress" placeholder=""
                                       autocomplete="off"
                                       class="layui-input" readonly="readonly">
                            </div>
                        </div>
                    </div>
                    </div>
                </div>
                <!--</div>
                <div class="layui-col-md9">-->
                <div class="layui-card">
                    <div class="layui-card-header">添加跟进记录</div>
                    <div class="layui-card-body">
                    <form class="layui-form " action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">客户ID</label>
                                <div class="layui-input-block">
                                    <input type="text" id="custId" name="custId" placeholder="" autocomplete="off"
                                           class="layui-input" readonly="readonly" required lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-inline" style="display: none">
                                <label class="layui-form-label">负责人ID</label>
                                <div class="layui-input-block">
                                    <input type="text" id="userId" name="userId" placeholder=""
                                           autocomplete="off"
                                           class="layui-input" onkeyup="this.value=this.value.replace(/\D/g,'')"
                                           onafterpaste="this.value=this.value.replace(/\D/g,'')" readonly="readonly">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">跟进方式</label>
                                <div class="layui-input-block">
                                    <select id="way" name="way">
                                        <option value=""></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">记录信息</label>
                            <div class="layui-input-block">
                    <textarea type="text" id="record" name="record" placeholder="" autocomplete="off"
                              class="layui-textarea"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-block">
                    <textarea type="text" id="remark" name="remark" placeholder="" autocomplete="off"
                              class="layui-textarea"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item ">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-card">
                    <div class="layui-card-header">历史跟进记录（此功能未来添加）</div>
                    <div class="layui-card-body layui-text">
                        还没有记录
                        <ul class="layui-timeline">
                            <li class="layui-timeline-item">
                                <i class="layui-icon layui-timeline-axis"></i>
                                <div class="layui-timeline-content layui-text">
                                    <h3 class="layui-timeline-title">8月18日</h3>
                                    <p>
                                        <br>
                                        <br> <i class="layui-icon"></i>
                                    </p>
                                </div>
                            </li>
                            <li class="layui-timeline-item">
                                <i class="layui-icon layui-timeline-axis"></i>
                                <div class="layui-timeline-content layui-text">
                                    <h3 class="layui-timeline-title">8月16日</h3>
                                    <p><em></em></p>
                                    <ul>
                                        <li></li>
                                        <li></li>
                                    </ul>
                                </div>
                            </li>
                            <li class="layui-timeline-item">
                                <i class="layui-icon layui-timeline-axis"></i>
                                <div class="layui-timeline-content layui-text">
                                    <h3 class="layui-timeline-title">8月15日</h3>
                                    <p>
                                        <br>
                                        <br>
                                        <br>
                                        <br>
                                    </p>
                                </div>
                            </li>
                            <li class="layui-timeline-item">
                                <i class="layui-icon layui-timeline-axis"></i>
                                <div class="layui-timeline-content layui-text">
                                    <div class="layui-timeline-title">过去</div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="lib/layui-v2.5.5/layui.all.js" charset="utf-8"></script>
<script src="js/lay-module/tableSelect/tableSelect.js"></script>
<script>
    layui.use('form', function () {
        var form = layui.form;
        //form.render();
        var tableSelect = layui.tableSelect;
        var $ = layui.jquery;
        <!--表单下拉选择-->
        $.ajax({
            url: "getFollowWayDict",
            type: "GET",
            datatype: "json",
            success: function (result) {
                console.log(result);   //{custIndustry: {…}, custLevel: {…}, custSource: {…}}
                for (var p in result) {
                    //console.log(p);  //p的值为custSource，result[p]为custSource的对应json字符窜
                    var type = result[p];
                    var custType = document.getElementById(p); //server为select定义的id，p："custIndustry"
                    for (var id in type) {
                        //console.log(result[p]);  //{1: "教育培训 ", 2: "电子商务", 3: "对外贸易", 4: "酒店旅游", 5: "房地产"}
                        //console.log(id);       //id
                        //console.log(type[id]);//值
                        var option = document.createElement("option");  // 创建添加option属性
                        option.setAttribute("value", id); // 给option的value添加值
                        option.innerText = type[id];     // 打印option对应的纯文本
                        custType.appendChild(option);           //给select添加option子标签
                        form.render("select");            // 刷性select，显示出数据
                    }
                }

            }
        });
        tableSelect.render({
            elem: '#custName',
            checkedKey: 'id',
            searchKey: 'custName',	//搜索输入框的name值 默认keyword
            searchPlaceholder: '客户名搜索',	//搜索输入框的提示文字 默认关键词搜索
            table: {
                url: 'customerList',
                request: {
                    pageName: 'page', //页码的参数名称，默认：pageNum
                    limitName: 'pageSize' //每页数据量的参数名，默认：pageSize
                },
                parseData: function (res) { //res 即为原始返回的数据
                    //res.code=0;
                    console.log(res);
                    return {
                        "code": 0, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.rows //解析数据列表
                    };
                },
                cols: [
                    [
                        {type: 'radio'},
                        {field: 'custId', title: 'ID'},
                        {field: 'custName', title: '客户名'},
                        {field: 'custLinkman', title: '联系人'},
                        {field: "custUserId", title: '负责人'}
                    ]
                ]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.custName);
                    $("#custId").val(item.custId);
                    $("#custId1").val(item.custId);
                    $("#custUserId").val(item.custUserId);
                    $("#userId").val(item.custUserId);
                    $("#custLinkman").val(item.custLinkman);
                    $("#custPhone").val(item.custPhone);
                    $("#custEmail").val(item.custEmail);
                    $("#custAddress").val(item.custAddress);
                    $("#custZipcode").val(item.custZipcode)
                });
                elem.val(NEWJSON.join(","))
            }
        });
        form.on("submit(formDemo)",function (data) {
            layer.confirm("是否提交",function () {
                $.ajax({
                    url: "saveFollowRecord",
                    data: data.field,
                    //dataType: 'JSON',
                    type: 'post',
                    success: function (data) {
                        //console.log(data.msg);
                        layer.msg(data.msg,  {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        },  function () {
                            //layer.closeAll();
                            parent.layer.close(parent.layer.index);
                            parent.layui.table.reload('currentTableId',{});
                        })
                    }
                });
            });
            return false;
        })
    })
</script>
</body>
</html>
